﻿using System.Drawing;
using Com.OpenCode.Framework.Core;
using DevExpress.XtraBars;

namespace Com.OpenCode.Framework.DevForm
{
    public class RightMenuSubItemUI : BarSubItem, IRightMenuProperty
    {
        public RightMenuSubItemUI(BuildItemEventArgs args)
        {
            args.Plugin.Owner = this;
            IRightMenuProperty _RightMenuProperty = args.Owner as IRightMenuProperty;
            OwnerRightMenu = _RightMenuProperty.OwnerRightMenu;
            Caption = args.Plugin.Properties.Get("Text").ToString();
            string _ImagePath = args.Plugin.Properties.Get("Image").ToString();
            PaintStyle = BarItemPaintStyle.CaptionGlyph;
            Plugin imagePlugin = args.Plugin.Addin.Plugin.Search("Icon", "Id", args.Plugin.Properties.GetString("Image"));
            if (imagePlugin != null)
            {
                Image image = (Image)args.Plugin.Addin.Bulid(imagePlugin, null);
                LargeGlyph = image;
                Glyph = image;
            }
            bool _BeginGroup = false;
            bool.TryParse(args.Plugin.Properties.Get("BeginGroup").ToString(), out _BeginGroup);
            _RightMenuProperty.BeginGroup = _BeginGroup;
            _RightMenuProperty.Add(this);
        }

        public OpenCodeRightMenuUI OwnerRightMenu { get; set; }
        public bool BeginGroup { get; set; }

        public void Add(BarItem item)
        {
            item.Manager = Manager;
            AddItem(item).BeginGroup = BeginGroup;
        }
    }
}